﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace CVSS.Client.BDM.Business
{
    class EditorHelper
    {
        #region 更改判定
        /// <summary>
        /// 当用户单击DataGridView列表的选项时，判定当前是否处于编辑状态.
        /// 无编辑状态返回false，有编辑状态返回true
        /// </summary>
        /// <param name="btn_Save"></param>
        /// <returns>无编辑状态返回false，有编辑状态返回true</returns>
        public static bool CheckItem(Button btn_Save, Button btn_Add)
        {
            try
            {
                if (btn_Save.Enabled)
                {
                    string msg = "所做的编辑未保存，确定要放弃保存吗？";
                    DialogResult dr = MessageBox.Show(
                        msg, "提示信息", MessageBoxButtons.YesNo,
                         MessageBoxIcon.Question);
                    if (dr == DialogResult.Yes)
                    {
                        btn_Save.Enabled = false;
                        btn_Add.Text = "增加";
                        return false;
                    }
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("调用EditorHelper.CheckItem()出错", ex);
            }
            return false;
        }
        #endregion

        public static void SetControlEnable(bool enable, Control[] Ctrls)
        {
            try
            {
                foreach (Control ctrl in Ctrls)
                {
                    ctrl.Enabled = enable;
                }
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("调用EditorHelper.SetControlEnable()出错", ex);
            }
        }
    }
}
